import 'dart:convert' show json;

import 'package:mahjong/entity/AbstractResult.dart';

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class Restful extends AbstractResult<Restful> {
  Restful({
    this.code,
    this.msg,
    this.body,
  });

  factory Restful.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Restful(
          code: asT<String>(jsonRes['code']),
          msg: asT<String>(jsonRes['msg']),
          body: asT<Object>(jsonRes['body']),
        );

  String code;
  String msg;
  Object body;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'code': code,
        'msg': msg,
        'body': body,
      };

  @override
  String toString() {
    return json.encode(this);
  }

  @override
  formJSON(Map<String, dynamic> jsonRes) {
    return Restful.fromJson(jsonRes);
  }

  fromJson(param0) {}
}
